/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mapcontrol.maplisteners;

import imgparser.ImgFileBag;
import imgparser.SubDivision;
import imgparser.labels.Label;
import java.awt.Point;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import mapcontrol.ImgConstants;
import mapcontrol.MapConfig;

/**
 *
 * @author Pieter
 */
public class LineSelector implements MapListener {

    private final MapConfig config;
    private final MapListener next;

    public LineSelector(MapConfig config, MapListener next) {
        this.config = config;
        this.next = next;
    }

    @Override
    public void addPoint(int type, int subType, int longitude, int latitude, Label label, boolean indexed) {
        next.addPoint(type, subType, longitude, latitude, label, indexed);
    }

    @Override
    public void addPoly(int type, int[] longitudes, int[] latitudes, int nbPoints, Label label, boolean line, boolean direction) {
        if (line) {
            next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
        } else {
            next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
        }
    }

    @Override
    public void startMap(ImgFileBag file) {
        next.startMap(file);
    }

    @Override
    public void startSubDivision(SubDivision subDivision) {
        next.startSubDivision(subDivision);
    }

    @Override
    public void finishPainting() {

        if (config.getSelected2Lines() != null) {
            for (Polygon selectedLine : config.getSelected2Lines()) {
                next.addPoly(ImgConstants.SELECTED_LINE2, selectedLine.xpoints, selectedLine.ypoints, selectedLine.npoints, null, true, false);
            }
        }
        if (config.getSelectedLine() != null) {
            next.addPoly(ImgConstants.SELECTED_LINE, config.getSelectedLine().xpoints, config.getSelectedLine().ypoints, config.getSelectedLine().npoints, null, true, false);
        }
        if (config.getCrossPoints() != null) {
            for (Point point : config.getCrossPoints()) {
                next.addPoint(ImgConstants.SELECTED_POINT >> 8, ImgConstants.SELECTED_POINT | 0xff, point.x, point.y, null, false);
            }
        }
        next.finishPainting();
    }
}
